package com.wanxi.app.controller.api;

import com.wanxi.app.domain.dto.AppLogin;
import com.wanxi.app.domain.result.AppResult;
import com.wanxi.app.service.user.LoginService;

import com.wanxi.login.domain.dto.LoginParamsDto;
import com.wanxi.login.domain.dto.PasswordDto;
import com.wanxi.login.domain.entity.TokenVo;
import com.wanxi.login.domain.result.LoginResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Author:wgy
 * @Data：2022/1/13 13:59
 */
@RestController
@RequestMapping
@Api(tags = "c端登陆")
public class LoginApi {
    @Resource
    private LoginService loginService;

    /**
     * 登陆
     * @param loginParamsDto  登陆信息
     * @return
     */
    @ApiOperation(value = "登陆接口")
    @PostMapping("login")
    public LoginResult<TokenVo> login(LoginParamsDto loginParamsDto){
        return loginService.login(loginParamsDto);
    }

    /**
     * c端用户注册
     *
     * @param appLogin
     * @return
     */
    @ApiOperation(value = "用户注册")
    @PostMapping("add")
    public LoginResult<Boolean> addLogin(AppLogin appLogin){
        return loginService.add(appLogin);
    }


    /**
     * c端获取邮箱
     *
     * @param email 邮箱
     * @return
     */
    @ApiOperation(value = "发送验证码")
    @PostMapping("fetchCode")
    public AppResult<String> fetchCode(String email){
        return loginService.fetchCode(email);
    }
    /**
     * 修改密码
     *
     * @param passwordDto
     * @return
     */
    @ApiOperation(value = "修改密码")
    @PutMapping("updatePasswordById")
    public LoginResult<Boolean> updatePasswordById(PasswordDto passwordDto){
        return loginService.updatePasswordById(passwordDto);
    }
}
